package com.open.basic.constant;

import com.open.basic.BasePageRequest;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author system
 * @Date 2023/12/4 18:16
 * @description 分页查询
 */
public class PageQuery extends BasePageRequest implements Serializable {

    private static final long serialVersionUID = 8828968957435128533L;

    private int totalCount;
    /**
     * 查询参数 精确匹配
     */
    private Map<String, Object> params;

    /**
     * 排序字段 正序 如 id
     */
    private List<String> orderFieldAscList = new ArrayList<>();
    /**
     * 排序字段 倒序 如 id
     */
    private List<String> orderFieldDescList = new ArrayList<>();

    public PageQuery() {
    }

    public PageQuery(int pageSize, int pageNo) {
        super(pageSize, pageNo);
    }

    public PageQuery(int pageSize, int pageNo, Map<String, Object> params) {
        super(pageSize, pageNo);
        this.params = params;
    }

    public PageQuery(int pageSize, int pageNo, int totalCount, Map<String, Object> params) {
        super(pageSize, pageNo);
        this.totalCount = totalCount;
        this.params = params;
    }

    public void addParam(String key, Object value) {
        if (params == null) {
            params = new ConcurrentHashMap<>();
        }
        params.put(key, value);
    }

    public int getTotalCount() {
        return totalCount;
    }

    public PageQuery setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        return this;
    }

    public Map<String, Object> getParams() {
        return params;
    }

    public PageQuery setParams(Map<String, Object> params) {
        this.params = params;
        return this;
    }


    public List<String> getOrderFieldAscList() {
        return orderFieldAscList;
    }

    public List<String> getOrderFieldDescList() {
        return orderFieldDescList;
    }

    public void addOrderFieldAsc(String orderField) {
        orderFieldAscList.add(orderField);
    }

    public void addOrderFieldDesc(String orderField) {
        orderFieldDescList.add(orderField);
    }
}
